﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var conStr = "server=.;database=Text;uid=sa;pwd=123456";

            SqlConnection sqlConnection = new SqlConnection(conStr);

            sqlConnection.Open();

            SqlCommand sqlCommand = new SqlCommand("select * from Userw", sqlConnection);
            //查询

          //  var reader = sqlCommand.ExecuteReader();

          /*  while (reader.Read())
            {
                Console.WriteLine("{0}\t,{1}\t,{2}\t,{3}\t,{4}\t", reader[0], reader[1], reader[2], reader[3], reader[4]);
            }*/


            //添加
            var insertStr = string.Format("insert into Userw(Username, Password)values('admin1', 'admin2')");

            SqlCommand cnm = new SqlCommand(insertStr, sqlConnection);

            var res = cnm.ExecuteNonQuery();
            Console.WriteLine(res);

            //更新

            var updateStr = "update Userw set Password='5555' where id = 3";
            SqlCommand com = new SqlCommand(updateStr, sqlConnection);
            var t = com.ExecuteNonQuery();
            Console.WriteLine(t);

        }
    }
}
